package com.tjn.try_;

import com.tjn.exception_.NullPointerException_;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class TryCatchDetail02 {
    public static void main(String[] args) {
        //4.可以有多个catch语句来捕获不同的异常，但是要求父类异常在后，子类异常在前
        //因为如果父类异常在前，就把异常都捕获了，子类的异常无法捕获，就会报错
        try {
            A a = new A();
            a = null;
            System.out.println(a.getN1());//空指针异常
            int b = 10;
            int c = 0;
            System.out.println(b/c);//算数异常
        }
        catch(NullPointerException e){
            System.out.println("空指针异常=" + e.getMessage());
        }catch (ArithmeticException e) {
            System.out.println("算数异常" + e.getMessage());
        }catch (Exception e) {
            System.out.println("Exception异常=" + e.getMessage());
        }
        finally {
            System.out.println("程序继续");
        }
    }
}
class A{
    private int n1;

    public int getN1() {
        return n1;
    }
}